package com.dykj.fireFighting.web.xfxg;

import com.dykj.fireFighting.api.socialUnit.xfxg.dto.PatrolReportDto;
import com.dykj.fireFighting.api.socialUnit.xfxg.entity.PatrolReport;
import com.dykj.fireFighting.api.socialUnit.xfxg.service.IPatrolReportService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.exception.BaseException;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.ApiImplicitParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;



/**
 * 消防巡更-巡更报告接口
 *
 * @Author LIJIANJIE
 * @Date  2021-06-23 11:19:32
 */
@Slf4j
@Api(value = "消防巡更-巡更报告接口", tags = {"消防巡更-巡更报告接口"})
@RestController
@RequestMapping("/patrolReport")
public class PatrolReportController {

    @DubboReference
    private IPatrolReportService patrolReportService;

    /**
     * 获取单位id
     * @return String
     */
    public String getEnterpriseId() {
        try {
            return Long.toString(ShiroUtil.getUser().getEnterpriseId());
        } catch (NullPointerException e) {
            e.printStackTrace();
            throw new BaseException("请登录系统");
        }
    }

    /**
     * 消防巡更报告列表
     *
     * @return
     */
    @AutoLog(value = "消防巡更-巡更报告-分页列表查询")
    @ApiOperation(value = "消防巡更-巡更报告分页列表", notes = "消防巡更-巡更报告分页列表")
    @GetMapping("/list")
    //@RequiresPermissions("unit/patrolReport/list")
    public CommonResult<PageVo<PatrolReport>> treeGrid(PatrolReportDto commonDto) {
        if (StringUtils.isBlank(commonDto.getUnitId())) {
            if (StringUtils.isBlank(getEnterpriseId())) {
                throw new BaseException("请登录系统");
            }
            commonDto.setUnitId(getEnterpriseId());
        }
        PageVo<PatrolReport> page = patrolReportService.pageList(commonDto);
        return CommonResult.success(page);
    }

    /**
     * 获取消防巡更-巡更报告信息
     */
    @AutoLog(value = "消防巡更-巡更报告-获取消防巡更-巡更报告信息")
    @ApiOperation(value = "获取消防巡更-巡更报告信息", notes = "获取消防巡更-巡更报告信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", dataType = "String", required = true)
    @GetMapping("/info/{id}")
    public CommonResult<PatrolReport> info(@PathVariable("id") String id){
        PatrolReport patrolReport = patrolReportService.getById(id);
        return CommonResult.success(patrolReport);
    }

    /**
     * 保存消防巡更-巡更报告信息
     */
    /*@AutoLog(value = "消防巡更-巡更报告-保存消防巡更-巡更报告信息")
    @ApiOperation(value = "保存消防巡更-巡更报告信息", notes = "保存消防巡更-巡更报告信息")
    @PostMapping("/save")
    @RequiresPermissions("unit/patrolReport/save")
    public CommonResult save(@Valid @RequestBody PatrolReport patrolReport) {
        try {
            patrolReport.setCreateTime(new Date());
            patrolReport.setUpdateTime(new Date());
                patrolReportService.save(patrolReport);
            return CommonResult.success("添加成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }*/

    /**
     * 修改消防巡更-巡更报告信息
     */
    /*@AutoLog(value = "消防巡更-巡更报告-修改消防巡更-巡更报告信息")
    @ApiOperation(value = "修改消防巡更-巡更报告信息", notes = "修改消防巡更-巡更报告信息")
    @PostMapping("/update")
    @RequiresPermissions("unit/patrolReport/update")
    public CommonResult update(@Valid @RequestBody PatrolReport patrolReport) {
        try {
            patrolReport.setUpdateTime(new Date());
                patrolReportService.updateById(patrolReport);
            return CommonResult.success("修改成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }*/

    /**
     * 删除消防巡更-巡更报告信息
     */
    /*@AutoLog(value = "消防巡更-巡更报告-删除消防巡更-巡更报告信息")
    @ApiOperation(value = "删除消防巡更-巡更报告信息", notes = "删除消防巡更-巡更报告信息")
    @ApiImplicitParam(paramType = "query", name = "ids", value = "ID数组", dataType = "String", required = true, allowMultiple = true)
    @PostMapping("/delete")
    @RequiresPermissions("unit/patrolReport/delete")
    public CommonResult delete(@RequestBody String[]ids) {
        try {
                patrolReportService.removeByIds(Arrays.asList(ids));
            return CommonResult.success("删除成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }*/
}
